package com.corpgovernment.common.enums;

import com.google.common.collect.Lists;

import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;

public enum CancelPolicyEnum {
    None(0, "无效值,未知", "无效值,未知"),
    FreeCancel(1, "免费取消", "预订后可随时免费取消，请放心预订"),
    LimitedCancel(2, "限时取消", "{0}之前可免费取消，请放心预订"),
    OverTimeGuaranteeLimitedCancel(4, "超时担保,有限制取消", ""),
    CanNotCancel(8, "不能取消", "订单确认后不可取消或修改");

    private Integer type;
    private String title;
    private String desc;

    CancelPolicyEnum(Integer type, String title, String desc) {
        this.type = type;
        this.title = title;
        this.desc = desc;
    }

    public Integer getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public String getTitle() {
        return title;
    }

    public static CancelPolicyEnum getByType(Integer type) {
        CancelPolicyEnum cancelPolicyEnum = Arrays.stream(CancelPolicyEnum.values()).filter(e -> e.getType().equals(type)).findFirst().orElse(null);
        return cancelPolicyEnum;
    }

    public static List<String> getCancelDetail(Integer policyType, String lastCancelTime) {
        CancelPolicyEnum policyEnum = CancelPolicyEnum.getByType(policyType);
        if (policyEnum == null){
            return null;
        }
        String desc = policyEnum.getDesc();
        String cancelDetail = MessageFormat.format(desc, lastCancelTime);
        return Lists.newArrayList(cancelDetail);
    }
}
